<?php

namespace app\common\model;
use think\Model;

class Message extends Model {

    /**
     * 定义主键
     * @var string
     */
    protected $pk = 'msg_id';
    
    /**
     * @desc 添加用户消息
     * @param int $userId
     * @param string $contents
     * @return int|string
     */
    public function addMessage($contents, $userId = 0) {
        return $this->where(['msg_user_id' => $userId])
            ->insertGetId([
                'msg_user_id' => $userId,
                'msg_contents' => $contents
            ]);
    }
}